import java.net.Socket;
import java.io.*;

class client{
    String ip;
    int port;
    Socket socket;
    ObjectInputStream in;
    PrintWriter out;
    
    public client(String ip,int port){
        this.ip=ip;
        this.port=port;
        try{
            Connect();
            CreateFile(GetObject());
        }
        catch(java.net.UnknownHostException e){
            System.out.println(e);
            System.out.println("error couldnt find host");
        }
        catch(java.io.IOException e){
            System.out.println(e);
            System.out.println("error couldnt establish connection");
        }
        catch(java.lang.ClassNotFoundException e){
            System.out.println(e);
            System.out.println("I dont really know");
        }
    }
    public void Connect()throws java.net.UnknownHostException,IOException{
        socket=new Socket(ip,port);
        in=new ObjectInputStream(socket.getInputStream());
        out=new PrintWriter(socket.getOutputStream(),true);
    }
    public void CreateFile(Object o1)throws IOException{
        FileOutputStream fos = new FileOutputStream("clientfile.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(o1);
        oos.close();
    }
    public void SendString(String message){
        out.println(message);
    }
    public byte[] GetByte()throws java.io.IOException,java.lang.ClassNotFoundException{
        return (byte[])in.readObject();
    }
    public Object GetObject()throws IOException,java.lang.ClassNotFoundException{
        return in.readObject();
    }
    public static void main(String arg[]){
        String ip="localhost";
        int port=8899;
        new client(ip,port);
    }
}
